package gatperdut.chato.core.interpreter.actions;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.core.characters.BaseController;
import gatperdut.chato.core.interpreter.actions.generic.CommunicationAction;
import gatperdut.chato.core.interpreter.grammar.comminfo.CommunicationInfo;

public class SayAction extends CommunicationAction {

    public SayAction( CommunicationInfo info, BaseController controller ) {
        super( info, controller );
    }

    @Override
    public CommandExecutionResult perform() {
        checkForRunningCraft();

        if ( emptyEmote() ) {
            getEntityController().tx( "Empty emotes are not allowed." );
            return CommandExecutionResult.OK;
        }
        // getInfo().getSpeech()
        if ( invalidSpeech() ) {
            getEntityController().tx( "What do you want to say?" );
            return CommandExecutionResult.OK;
        }

        String emote = getLastPartEmote();
        if ( emote == null ) {
            getEntityController().tx( "Check your emote." );
            return CommandExecutionResult.OK;
        }

        getEntityController().getEchoes().txSay( emote, getInfo().getSpeech() );

        return CommandExecutionResult.OK;
    }

}
